<?php

class internetsaude extends controller {

    public function reportagens() {
        
    }

    public function academicos() {
        
    }

    public function videos() {
        // Call set_include_path() as needed to point to your client library.
        require_once pluginPath . 'google-api-php-client/Google_Client.php';
        require_once pluginPath . 'google-api-php-client/contrib/Google_YouTubeService.php';

        $DEVELOPER_KEY = 'AIzaSyAOMmIC52N6IlQEjtC3omPUKfxEjx7K2x4';

        $client = new Google_Client();
        $client->setDeveloperKey($DEVELOPER_KEY);

        $youtube = new Google_YoutubeService($client);

        try {
            $searchResponse = $youtube->search->listSearch('id,snippet', array(
                'q' => '',
                'maxResults' => 9,
                'channelId' => 'UCaULpqfc1ni5Jc_cIgp3n1Q',
                'order' => 'date'
            ));

            $videos = array();
            foreach ($searchResponse['items'] as $searchResult) {
                if ($searchResult['id']['kind'] == 'youtube#video') {
                    $videos[$searchResult['id']['videoId']]['title'] = $searchResult['snippet']['title'];
                    $videos[$searchResult['id']['videoId']]['description'] = $searchResult['snippet']['description'];
                    $videos[$searchResult['id']['videoId']]['publishedAt'] = $searchResult['snippet']['publishedAt'];
                    $videos[$searchResult['id']['videoId']]['thumbnail'] = $searchResult['snippet']['thumbnails']['default']['url'];
                }
            }
            return array('videos' => $videos);
        } catch (Google_ServiceException $e) {
            $this->log($e->getMessage(), 500);
        } catch (Google_Exception $e) {
            $this->log($e->getMessage(), 500);
        }
    }

    public function sites() {
        
    }

}
?>
